""" System imports """
import logging

""" Other modules """

""" Game """
import events

""" Constants """


""" Set up logging """
_log = logging.getLogger("equinox.eventrouter")


""" Set up logging """
_log = logging.getLogger("epicquest.eventrouter")

class EventRouter():
        
    """ Class to handle all event routing
    """    
    def __init__(self):
        from weakref import WeakKeyDictionary
        self.listeners = WeakKeyDictionary()
        self.event_queue = []
    
    
    def registerListener(self, listener):
        self.listeners [listener] = 1
    
    
    def unregisterListener(self, listener):
        if listener in self.listeners:
            del self.listeners[listener]
    
    def post(self, event):
        if not isinstance(event, events.TickEvent):
            _log.debug("Event:" + event.name)
        for listener in self.listeners:
            listener.notify(event)
            
        
# Module level instance. Don't make any more. That would be silly
eventpanel = EventRouter()

if __name__ == "__main__":
    import unittest
    
    class EventTest(unittest.TestCase):
    
        def setUp(self):
            pass
    
    unittest.main()
    


